//---------------------------------------------------------------------------

#ifndef FrameProviderBridgeH
#define FrameProviderBridgeH

#include <dbtables.hpp>
#include "StringUtilities.h"

class TFrameProvider : public TObject
{
   public:
      __int64 id;
      AnsiString name;
      AnsiString address;
      AnsiString phone;

      TFrameProvider();
      TFrameProvider( TFrameProvider* other);
};

class TFrameOrder : public TObject
{
   public:
      __int64 id;
      __int64 frameProviderID;
      TDateTime orderDate;
      __int64 invoiceNumber;
      Currency amount;

      TFrameOrder();
      TFrameOrder( TFrameOrder* other);
      
      bool IsEqual( TFrameOrder* other);
      AnsiString GetKey();
};

class TFrameRefund : public TObject
{
   public:
      __int64 id;
      __int64 frameProviderID;
      TDateTime refundDate;
      Currency amount;

      TFrameRefund();
      TFrameRefund( TFrameRefund* other);
      
      bool IsEqual( TFrameRefund* other);
      AnsiString GetKey();
};

class TFrameProviderBridge
{
   public:
      TFrameProviderBridge( TDatabase * database);
      ~TFrameProviderBridge();

      void Get( __int64 id, TFrameProvider* provider);
      void Add( TFrameProvider* provider);
      void Update( TFrameProvider* provider);
      void Delete( __int64 id);
      void GetProviders( TStrings * providers);

      void GetOrders(__int64 frameProviderID, TStrings * orders);
      void GetRefunds(__int64 frameProviderID, TStrings * refunds);

      void AddOrder( TFrameOrder* order);
      void UpdateOrder( __int64 id, TFrameOrder* order);
      void DeleteOrder( __int64 id);

      void AddRefund( TFrameRefund* order);
      void UpdateRefund( __int64 id, TFrameRefund* refund);
      void DeleteRefund( __int64 id);
      
   private:
      TQuery * qryGet;
      TQuery * qryAdd;
      TQuery * qryUpdate;
      TQuery * qryDelete;
      TQuery * qryGetFrameProviders;

      TQuery * qryGetOrders;
      TQuery * qryGetRefunds;
      TQuery * qryDeleteOrders;
      TQuery * qryDeleteRefunds;

      TQuery * qryAddOrder;
      TQuery * qryUpdateOrder;
      TQuery * qryDeleteOrder;
      TQuery * qryAddRefund;
      TQuery * qryUpdateRefund;
      TQuery * qryDeleteRefund;

      void BuildGetQuery();
      void BuildAddQuery();
      void BuildUpdateQuery();
      void BuildDeleteQuery();
      void BuildGetFrameProvidersQuery();

      void BuildGetOrdersQuery();
      void BuildGetRefundsQuery();
      void BuildDeleteOrdersQuery();
      void BuildDeleteRefundsQuery();

      void BuildAddOrderQuery();
      void BuildUpdateOrderQuery();
      void BuildDeleteOrderQuery();
      void BuildAddRefundQuery();
      void BuildUpdateRefundQuery();
      void BuildDeleteRefundQuery();
};

#endif
